import { defineStore } from "pinia";
import {computed, ref} from 'vue'

export const useGoods = defineStore('goods',()=>{
  // 定义state
  const goodsList = ref([
    {name:'商品名称',price:100},
    {name:'商品名称1',price:101},
  ])
  //定义actions
  const goodsAdd = (goodsObj)=>{
    goodsList.value.push(goodsObj)
  }
  //定义getters
  const filterGoodsList = computed(()=>{
    return goodsList.value.filter(item=>item.price<=100)
  })
  return {
    goodsList,
    goodsAdd,
    filterGoodsList
  }
},{persist:true})